﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Middleware
{
    /// <summary>
    /// Usado para acessar o objeto remoto usando o Client Request Handler
    /// </summary>
    public static class Requestor
    {
        public static MessageReply Request(IOR ior, string methodName, bool hasReturnValue, params object[] ps) {
            ClientRequestHandler clientRequestHandler = new ClientRequestHandler(ior);
            MessageRequest requestMessage = new MessageRequest();
            requestMessage.ObjectID = ior.ObjectID;
            requestMessage.MethodName = methodName;
            requestMessage.HasReturnValue = hasReturnValue;
            requestMessage.Parameters = ps;
            byte[] messageRequestArray = Marshaller.GetBytes(requestMessage);
            byte[] messageReplyArray = clientRequestHandler.Send(messageRequestArray, true);
            MessageReply messageReply = Marshaller.GetMessage(messageReplyArray) as MessageReply;
            return messageReply;
        }
    }
}
